package com.cn.bulu.service.impl;

import com.cn.bulu.dao.HomePageDao;
import com.cn.bulu.pojo.Composition;
import com.cn.bulu.pojo.Customer;
import com.cn.bulu.pojo.Picture;
import com.cn.bulu.pojo.Sample;
import com.cn.bulu.service.HomePageService;
import com.cn.bulu.utils.BuluResult;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("homePageService")
public class HomePageServiceImpl implements HomePageService {
	
	private static Logger logger = Logger.getLogger(HomePageServiceImpl.class);
	@Resource 
	private HomePageDao homePageDao;
	//搜索
	public BuluResult searchSample(String search , Integer page,Integer type){
		Map<String, Object> map = new HashMap<String,Object>();
		BuluResult buluResult = new BuluResult();
		//防止直接访问接口服务器报错
		if(null==page || null==search ){
			buluResult.setStatus(1);
			buluResult.setMessage("请输入搜索关键字......");
			return buluResult;
		}
		page=10*(page-1);
		map.put("search", search.trim());
		map.put("page", page);
		map.put("type", type);
		List<Sample> list = homePageDao.searchSample(map);
		if(list!=null&&list.size()!=0){
			List<Sample> list2 = CXXL(list);
			buluResult.setStatus(0);
			buluResult.setData(list2);
			return buluResult;
		}else{
			buluResult.setStatus(1);
			buluResult.setMessage("没有搜索到相关商品!");
			return buluResult;
		}
	}

	//加载首页
	public BuluResult selectHomePage(Integer type, Integer page) {
		Map<String, Object> map = new HashMap<String, Object>();
		BuluResult buluResult = new BuluResult();
		page=10*(page==null?0:page-1);
		map.put("type", type==null?0:type);
		map.put("page", page);
		List<Sample> list = homePageDao.selectHomePage(map);
		if(list!=null&&list.size()!=0){
			List<Sample> list2 = CXXL(list);
			buluResult.setStatus(0);
			buluResult.setData(list2);
			return buluResult;
		}else{
			buluResult.setStatus(1);
			buluResult.setMessage("这回真没有了......");
			return buluResult;
		}
	}

	//加载菜单栏
	public BuluResult selectMenu(Integer type) {
		BuluResult buluResult = new BuluResult();
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		Map<String, Object> map1 = new HashMap<String,Object>();
		map1.put("title", "品牌");
		map1.put("key", "brand");
		List<Map<String, Object>> brandList = homePageDao.selectBrand();
		for(int a=0;a<brandList.size();a++){
			brandList.get(a).put("bodyid", brandList.get(0).get("brand"));
			brandList.get(a).put("body", brandList.get(a).get("brand"));
			brandList.get(a).remove("brand");
		}
		map1.put("titleBody", brandList);
		list.add(map1);
		Map<String, Object> map2 = new HashMap<String,Object>();
		map2.put("title", "筛选");
		map2.put("key", "keyword");
		List<Map<String, Object>> screenList = new ArrayList<Map<String, Object>>();
		Map<String, Object> map3 = new HashMap<String,Object>();
		map3.put("bodyid", "priceS");
		map3.put("body", "价格 ↑");
		screenList.add(map3);
		Map<String, Object> map4 = new HashMap<String,Object>();
		map4.put("bodyid", "priceJ");
		map4.put("body", "价格 ↓");
		screenList.add(map4);
		Map<String, Object> map5 = new HashMap<>();
		map5.put("bodyid", "saleCountS");
		map5.put("body", "销量 ↑");
		screenList.add(map5);
		Map<String, Object> map6 = new HashMap<>();
		map6.put("bodyid", "saleCountJ");
		map6.put("body", "销量 ↓");
		screenList.add(map6);
		map2.put("titleBody", screenList);
		list.add(map2);
		if(null==type){
			buluResult.setStatus(0);
			buluResult.setData(list);
			return buluResult;
		}
		switch (type) {
		case 0:
			Map<String, Object> map7 = new HashMap<>();
			map7.put("title", "风格");
			map7.put("key", "styleId");
			List<Map<String, Object>> styleList = homePageDao.selectStyle();
			map7.put("titleBody", styleList);
			for(int a=0;a<styleList.size();a++){
				styleList.get(a).put("bodyid", styleList.get(a).get("styleId"));
				styleList.get(a).put("body", styleList.get(a).get("styleContent"));
				styleList.get(a).remove("styleId");
				styleList.get(a).remove("styleContent");
			}
			list.add(map7);
			Map<String, Object> map8 = new HashMap<>();
			map8.put("title", "适用场景");
			map8.put("key", "locationId");
			List<Map<String, Object>> locationList = homePageDao.selectLocation();
			map8.put("titleBody", locationList);
			for(int a=0;a<locationList.size();a++){
				locationList.get(a).put("bodyid", locationList.get(a).get("locationId"));
				locationList.get(a).put("body", locationList.get(a).get("locationContent"));
				locationList.get(a).remove("locationId");
				locationList.get(a).remove("locationContent");
			}
			list.add(map8);
			Map<String, Object> map9 = new HashMap<>();
			map9.put("title", "结构");
			map9.put("key", "structure");
			List<Map<String, Object>> structureList = new ArrayList<>();
			Map<String, Object> map10 = new HashMap<>();
			map10.put("bodyid", 0);
			map10.put("body", "单布");
			structureList.add(map10);
			Map<String, Object> map11 = new HashMap<>();
			map11.put("bodyid", 1);
			map11.put("body", "单纱");
			structureList.add(map11);
			Map<String, Object> map12 = new HashMap<>();
			map12.put("bodyid", 2);
			map12.put("body", "布+纱");
			structureList.add(map12);
			map9.put("titleBody", structureList);
			list.add(map9);
			Map<String, Object> map13 = new HashMap<>();
			List<Map<String, Object>> CG = new ArrayList<>();
			Map<String, Object> mapcg = new HashMap<>();
			mapcg.put("bodyid", 3);
			mapcg.put("body", "超高");
			CG.add(mapcg);
			map13.put("title", "特殊");
			map13.put("key", "CG");
			map13.put("titleBody", CG);
			list.add(map13);
			break;
		case 1:
//			Map<String, Object> map14 = new HashMap<String,Object>();
//			map14.put("title", "适用场景");
//			map14.put("key", "locationId");
//			List<Map<String, Object>> locationList2 = homePageDao.selectLocation();
//			for(int a=0;a<locationList2.size();a++){
//				locationList2.get(a).put("bodyid", locationList2.get(a).get("locationId"));
//				locationList2.get(a).put("body", locationList2.get(a).get("locationContent"));
//				locationList2.get(a).remove("locationId");
//				locationList2.get(a).remove("locationContent");
//			}
//			map14.put("titleBody", locationList2);
//			list.add(map14);
			Map<String, Object> map15 = new HashMap<String,Object>();
			map15.put("title", "类型");
			map15.put("key", "fptId");
			List<Map<String, Object>> typeList = homePageDao.selectFPT();
			map15.put("titleBody", typeList);
			for(int a=0;a<typeList.size();a++){
				typeList.get(a).put("bodyid", typeList.get(a).get("fptId"));
				typeList.get(a).put("body", typeList.get(a).get("fptBody"));
				typeList.get(a).remove("fptId");
				typeList.get(a).remove("fptBody");
			}
			list.add(map15);
			Map<String, Object> mapZhe = new HashMap<>();
			mapZhe.put("title", "遮光情况");
			mapZhe.put("key", "shading");
			List<Map<String, Object>> ZheGList = new ArrayList<>();
			Map<String, Object> mapBan = new HashMap<>();
			mapBan.put("bodyid", 0);//理论上应该是int类型id，但由于没有遮光率的字典表，就先字符串了
			mapBan.put("body", "半遮光");
			ZheGList.add(mapBan);
			Map<String, Object> mapQuan = new HashMap<>();
			mapQuan.put("bodyid", 1);//理论上应该是int类型id，但由于没有遮光率的字典表，就先字符串了
			mapQuan.put("body", "全遮光");
			ZheGList.add(mapQuan);
			mapZhe.put("titleBody", ZheGList);
			list.add(mapZhe);
			break;
		case 2:
			Map<String, Object> map16 = new HashMap<>();
			map16.put("title", "类型");
			map16.put("key", "AccessoriesTypeId");
			List<Map<String, Object>> pjTypeList = homePageDao.selectPJ();
			map16.put("titleBody", pjTypeList);
			for(int a=0;a<pjTypeList.size();a++){
				pjTypeList.get(a).put("bodyid", pjTypeList.get(a).get("accessoriesTypeId"));
				pjTypeList.get(a).put("body", pjTypeList.get(a).get("accessoriesTypeContent"));
				pjTypeList.get(a).remove("accessoriesTypeId");
				pjTypeList.get(a).remove("accessoriesTypeContent");
			}
			list.add(map16);
			break;
		}
		buluResult.setStatus(0);
		buluResult.setData(list);
		return buluResult;
	}
	////////////////////////////////////筛选更改开始///////////////////////////////////////////////////
	/*public BuluResult selectScreen2(Integer type,String brand,Integer styleId
			,Integer locationId,String keyword,Integer structure,Integer CG
			,Integer fptId,Integer AccessoriesTypeId,Integer shading,Integer page) {
		//logger.error(type+" "+brand+" "+styleId+" "+locationId+" "+keyword+" "
		//+structure+" "+CG+" "+fptId+" "+AccessoriesTypeId+" "+obscuration+" "+page);
		BuluResult buluResult = new BuluResult();
		List<Sample> list = new ArrayList<>();
		Map<String, Object> map = new HashMap<>();
		page=10*(page-1);
		map.put("type", type);
		map.put("page", page);
		map.put("brand", brand);
		map.put("keyword", keyword);
		switch (type) {
		case 0:
			map.put("structure", structure);
			//判断风格是否选中
			if(styleId!=null&&styleId!=666){//风格选中
				//根据风格查询得到一个集合
				Integer[] sampleSTY = homePageDao.selectSampleStyle(styleId);
				//判断适用场景是否选中
				if(locationId!=null&&locationId!=666){//适用场景选中
					//筛选出两个集合中相同的集合
					Integer[] sampleIdS=new Integer[sampleSTY.length];
					//根据适用场景得到一个集合
					Integer[] sampleLOC = homePageDao.selectSampleLocation(locationId);
					int x=0;
					for(int a=0; a<sampleSTY.length;a++){
						for(int b=0; b<sampleLOC.length; b++){
							int aa = sampleSTY[a];
							int bb = sampleLOC[b];
							if(aa==bb){
								sampleIdS[x]=aa;
								x++;
							}
						}
					}
					//判断超高是否选中(超高是结构下面选项，若选中则单布..等等无法选中)
					if(CG!=null&&CG!=666){//超高选中
						//筛选出两个集合中相同的集合
						Integer[] IDS=new Integer[sampleIdS.length];
						//根据超高得到一个集合
						Integer[] CGS = homePageDao.selectCG();
						int l=0;
						for(int a=0; a<sampleIdS.length;a++){
							for(int b=0; b<CGS.length; b++){
								int aa = sampleIdS[a];
								int bb = CGS[b];
								if(aa==bb){
									IDS[l]=aa;
									l++;
								}
							}
						}
						//筛选后获得IDS集合调用查询语句
						map.put("sampleIdlist", IDS);
						List<Sample> list2 = homePageDao.selectKeyword(map);
						list = CXXL(list2);
					}else{//超高未选中
						//调用查询语句
						map.put("sampleIdlist", sampleIdS);
						List<Sample> list2 = homePageDao.selectKeyword(map);
						list = CXXL(list2);
					}
				}else{//适用场景未选中
					//判断超高是否选中(超高是结构下面选项，若选中则单布..等等无法选中)
					if(CG!=null&&CG!=666){//超高选中
						Integer[] IDS = new Integer[sampleSTY.length];
						int l=0;
						Integer[] CGS = homePageDao.selectCG();
						for(int a=0; a<sampleSTY.length;a++){
							for(int b=0; b<CGS.length; b++){
								int aa = sampleSTY[a];
								int bb = CGS[b];
								if(aa==bb){
									IDS[l]=aa;
								}
							}
						}
						map.put("sampleIdlist", IDS);
						List<Sample> list2 = homePageDao.selectKeyword(map);
						list = CXXL(list2);
						//获取筛选后list调用查询语句
					}else{//超高未选中
						//调用查询语句
						map.put("sampleIdlist", sampleSTY);
						List<Sample> list2 = homePageDao.selectKeyword(map);
						list = CXXL(list2);
					}
				}
			}else{//风格未选中
				//判断适用场景是否选中
				if(locationId!=null&&locationId!=666){//适用场景选中
					//根据适用场景的到一个集合
					Integer[] sampleLOC = homePageDao.selectSampleLocation(locationId);
					//判断超高是否选中(超高是结构下面选项，若选中则单布..等等无法选中)
					if(CG!=666&&CG!=null){//超高选中
						Integer[] IDS = new Integer[sampleLOC.length];
						int l=0;
						Integer[] CGS = homePageDao.selectCG();
						for(int a=0; a<sampleLOC.length;a++){
							for(int b=0; b<CGS.length; b++){
								int aa = sampleLOC[a];
								int bb = CGS[b];
								if(aa==bb){
									IDS[l]=aa;
								}
							}
						}
						//获取筛选后list调用查询语句
						map.put("sampleIdlist", IDS);
						List<Sample> list2 = homePageDao.selectKeyword(map);
						list = CXXL(list2);
					}else{//超高未选中
						//调用查询语句
						map.put("sampleIdlist", sampleLOC);
						List<Sample> list2 = homePageDao.selectKeyword(map);
						list = CXXL(list2);
					}
				}else{//适用场景未选中
					//判断超高是否选中(超高是结构下面选项，若选中则单布..等等无法选中)
					if(CG!=null&&CG!=666){//超高选中
						//获取筛选后list调用查询语句
						Integer[] CGS = homePageDao.selectCG();
						map.put("sampleIdlist", CGS);
						List<Sample> list2 = homePageDao.selectKeyword(map);
						list = CXXL(list2);
					}else{//超高未选中
						//调用查询语句
						map.put("sampleIdlist", null);
						List<Sample> list2 = homePageDao.selectKeyword(map);
						list = CXXL(list2);
					}
				}
			}
			break;
		case 1:
			map.put("fptId", fptId);//类型：1：百叶窗  2：卷帘  3：柔纱帘
			if (shading!=null) {
				if (shading==0) {
					map.put("shading", "半遮光");
				}else if(shading==1) {
					map.put("shading", "全遮光");
				}
			}else {
				map.put("shading", null);
			}
			List<Sample> list2 = homePageDao.selectScreen(map);
			list = CXXL(list2);
			break;
		default:
			map.put("AccessoriesTypeId", AccessoriesTypeId);
			List<Sample> list3 = homePageDao.selectScreen(map);
			list = CXXL(list3);
			break;
		}
		if(list!=null&&list.size()!=0){
			buluResult.setStatus(0);
			buluResult.setData(list);
			return buluResult;
		}else{
			buluResult.setStatus(1);
			buluResult.setMessage("没有搜索到相关商品!!!");
			return buluResult;
		}
	}*/
	public BuluResult selectScreen(Integer type,String brand,Integer styleId
			,Integer locationId,String keyword,Integer structure,Integer CG
			,Integer fptId,Integer AccessoriesTypeId,Integer shading,Integer page) {
		//logger.error(type+" "+brand+" "+styleId+" "+locationId+" "+keyword+" "
		//+structure+" "+CG+" "+fptId+" "+AccessoriesTypeId+" "+obscuration+" "+page);
		BuluResult buluResult = new BuluResult();
		List<Sample> list = new ArrayList<>();
		Map<String, Object> map = new HashMap<>();
		page=10*(page-1);
		map.put("type", type);
		map.put("page", page);
		map.put("brand", brand);
		map.put("keyword", keyword);
		switch (type) {
		case 0:
			map.put("structure", structure);
			//判断风格是否选中
			if(styleId!=null&&styleId!=666){//风格选中
				//根据风格查询得到一个集合
				List<Integer>sampleSTY=homePageDao.selectSampleStyle(styleId);
				//判断适用场景是否选中
				if(locationId!=null&&locationId!=666){//适用场景选中
					//筛选出两个集合中相同的集合
					List<Integer>sampleIdS=new ArrayList<Integer>();
					//根据适用场景得到一个集合
					List<Integer>sampleLOC = homePageDao.selectSampleLocation(locationId);
					for(int a=0; a<sampleSTY.size();a++){
						for(int b=0; b<sampleLOC.size(); b++){
							int aa = sampleSTY.get(a);
							int bb = sampleLOC.get(b);
							if(aa==bb){
								sampleIdS.add(aa);
							}
						}
					}
					//判断超高是否选中(超高是结构下面选项，若选中则单布..等等无法选中)
					if(CG!=null&&CG!=666){//超高选中
						//筛选出两个集合中相同的集合
						List<Integer>IDS=new ArrayList<Integer>();
						//根据超高得到一个集合
						List<Integer>CGS = homePageDao.selectCG();
						for(int a=0; a<sampleIdS.size();a++){
							for(int b=0; b<CGS.size(); b++){
								int aa = sampleIdS.get(a);
								int bb = CGS.get(b);
								if(aa==bb){
									IDS.add(aa);
								}
							}
						}
						//筛选后获得IDS集合调用查询语句
						if(IDS!=null&&IDS.size()>0) {
							map.put("sampleIdlist", IDS);
							List<Sample> list2 = homePageDao.selectKeyword(map);
							list = CXXL(list2);
						}
					}else{//超高未选中
						//调用查询语句
						if(sampleIdS!=null&&sampleIdS.size()>0) {
							map.put("sampleIdlist", sampleIdS);
							List<Sample> list2 = homePageDao.selectKeyword(map);
							list = CXXL(list2);
						}						
					}
				}else{//适用场景未选中
					//判断超高是否选中(超高是结构下面选项，若选中则单布..等等无法选中)
					if(CG!=null&&CG!=666){//超高选中
						ArrayList<Integer>IDS=new ArrayList<Integer>();
						List<Integer>CGS = homePageDao.selectCG();
						for(int a=0; a<sampleSTY.size();a++){
							for(int b=0; b<CGS.size(); b++){
								int aa = sampleSTY.get(a);
								int bb = CGS.get(b);
								if(aa==bb){
									IDS.add(aa);
								}
							}
						}
						if(IDS!=null&&IDS.size()>0) {
							map.put("sampleIdlist", IDS);
							List<Sample> list2 = homePageDao.selectKeyword(map);
							list = CXXL(list2);
						}
						//获取筛选后list调用查询语句
					}else{//超高未选中
						//调用查询语句
						if(sampleSTY!=null&&sampleSTY.size()>0) {
							map.put("sampleIdlist", sampleSTY);
							List<Sample> list2 = homePageDao.selectKeyword(map);
							list = CXXL(list2);
						}
					}
				}
			}else{//风格未选中
				//判断适用场景是否选中
				if(locationId!=null&&locationId!=666){//适用场景选中
					//根据适用场景的到一个集合
					List<Integer>sampleLOC=homePageDao.selectSampleLocation(locationId);
					//判断超高是否选中(超高是结构下面选项，若选中则单布..等等无法选中)
					if(CG!=666&&CG!=null){//超高选中
						List<Integer>IDS=new ArrayList<Integer>();
						List<Integer>CGS = homePageDao.selectCG();
						for(int a=0; a<sampleLOC.size();a++){
							for(int b=0; b<CGS.size(); b++){
								int aa = sampleLOC.get(a);
								int bb = CGS.get(b);
								if(aa==bb){
									IDS.add(aa);
								}
							}
						}
						//获取筛选后list调用查询语句
						if(IDS!=null&&IDS.size()>0) {
							map.put("sampleIdlist", IDS);
							List<Sample> list2 = homePageDao.selectKeyword(map);
							list = CXXL(list2);
						}
					}else{//超高未选中
						//调用查询语句
						if(sampleLOC!=null&&sampleLOC.size()>0) {
							map.put("sampleIdlist", sampleLOC);
							List<Sample> list2 = homePageDao.selectKeyword(map);
							list = CXXL(list2);
						}
					}
				}else{//适用场景未选中
					//判断超高是否选中(超高是结构下面选项，若选中则单布..等等无法选中)
					if(CG!=null&&CG!=666){//超高选中
						//获取筛选后list调用查询语句
						List<Integer>CGS = homePageDao.selectCG();
						if(CGS!=null&&CGS.size()>0) {
							map.put("sampleIdlist", CGS);
							List<Sample> list2 = homePageDao.selectKeyword(map);
							list = CXXL(list2);
						}					
					}else{//超高未选中
						//调用查询语句
						map.put("sampleIdlist", null);
						List<Sample> list2 = homePageDao.selectKeyword(map);
						list = CXXL(list2);
					}
				}
			}
			break;
		case 1:
			map.put("fptId", fptId);//类型：1：百叶窗  2：卷帘  3：柔纱帘
			if (shading!=null) {
				if (shading==0) {
					map.put("shading", "半遮光");
				}else if(shading==1) {
					map.put("shading", "全遮光");
				}
			}else {
				map.put("shading", null);
			}
			List<Sample> list2 = homePageDao.selectScreen(map);
			list = CXXL(list2);
			break;
		default:
			map.put("AccessoriesTypeId", AccessoriesTypeId);
			List<Sample> list3 = homePageDao.selectScreen(map);
			list = CXXL(list3);
			break;
		}
		if(list!=null&&list.size()!=0){
			buluResult.setStatus(0);
			buluResult.setData(list);
			return buluResult;
		}else{
			buluResult.setStatus(1);
			buluResult.setMessage("没有搜索到相关商品!!!");
			return buluResult;
		}
	}
	//查询系列通用方法
	public List<Sample> CXXL(List<Sample> list){
		//向商品中添加满减优惠信息
		Double measureMoneyOff = homePageDao.selectTerritoryByType(8).getMoney();
		Double installMoneyOff = homePageDao.selectTerritoryByType(9).getMoney();
		for(int a=0; a<list.size();a++){
			list.get(a).setMeasureMoneyOff(measureMoneyOff);//满减测量费
			list.get(a).setInstallMoneyOff(installMoneyOff);//满减安装费
			if(list.get(a).getType()==0){//布艺
				Double Sprice = homePageDao.selectSprice(list.get(a).getSampleId());
				if(Sprice!=null){
					list.get(a).setSsPrice(Sprice);//纱价格
				}
				if(list.get(a).getSwag()==1){//帘头：0没有  1有
					list.get(a).setLlPrice(homePageDao.selectLprice(list.get(a).getSampleId()));//帘头价格
				}
			}
			if(list.get(a).getSeries()!=null){
				List<Sample> samples = homePageDao.selectSeries(list.get(a).getSeries());
				for (Sample sample:samples) {
					sample.setMeasureMoneyOff(measureMoneyOff);
					sample.setInstallMoneyOff(installMoneyOff);
				}
				list.get(a).setSeriesList(samples);
			}
		}
		return list;
	}
	//查询商品详情
	public BuluResult selectXQ(Integer sampleId) {
		List<Picture> list = homePageDao.selectXQ(sampleId);
		BuluResult buluResult = new BuluResult();
		buluResult.setStatus(0);
		buluResult.setData(list);
		return buluResult;
	}

	//查询商品评价
	public BuluResult selectEvaluation(Integer sampleId,Integer page) {
		BuluResult buluResult = new BuluResult();
		Map<String, Object> map = new HashMap<>();
		//logger.error(page+"----------------------------");
		page = 10*(page-1);
		map.put("sampleId", sampleId);
		map.put("page", page);
		List<Map<String, Object>> list = homePageDao.selectEvaluation(map);
		if(list!=null&&list.size()!=0){
			for(int a=0; a<list.size();a++){
				Customer customer=homePageDao.getCustomerById((Integer)list.get(a).get("customerId"));
				list.get(a).put("nickName", customer.getNickName());
				list.get(a).put("headImg", customer.getHeadImg());
				List<String> PList = homePageDao.selectImg((Integer)list.get(a).get("evaluationId"));
				List<String> imgList = new ArrayList<>();
				imgList.addAll(PList);
				list.get(a).put("pictureS", imgList);
				
			}
			buluResult.setStatus(0);
			buluResult.setData(list);
			return buluResult;
		}else{
			buluResult.setStatus(1);
			buluResult.setMessage("暂无评价数据!!!");
			return buluResult;
		}
	}

	//查询产品图文详情和测量安装
	public BuluResult selectTuwen(Integer sampleId,Integer type) {
		List<Map<String,Object>> Tuwen = homePageDao.selectTuwen(sampleId);
		List<Map<String, String>> Kuanshi = homePageDao.selectKuanshi(sampleId);
		List<Map<String, Object>> xiangqing = new ArrayList<>();
		if(type==0){
			Map<String, Object> xiang = homePageDao.selectXiangqing(sampleId);
			List<String> list = homePageDao.selectStyleContent(sampleId);
			String style = "";
			for(int a=0;a<list.size();a++){
				if(a==list.size()-1){
					style += list.get(a);
				}else{
					style += list.get(a)+",";
				}
			}
			List<String> list2 = homePageDao.selectShiyong(sampleId);
			String location = "";
			for(int a=0;a<list2.size();a++){
				if(a==list2.size()-1){
					location += list2.get(a);
				}else{
					location += list2.get(a)+",";
				}
			}
			xiang.put("style", style);
			xiang.put("location", location);
			Map<String, Object> map1 = new HashMap<>();
			map1.put("boodyId", "品牌");
			map1.put("boody", xiang.get("brand"));
			xiangqing.add(map1);
			Map<String, Object> map2 = new HashMap<>();
			map2.put("boodyId", "商品号");
			map2.put("boody", xiang.get("sampleId"));
			xiangqing.add(map2);
			Map<String, Object> map3 = new HashMap<>();
			map3.put("boodyId", "材质");
			if(type==0){
				//布艺帘
				StringBuffer s=new StringBuffer();
				List<Composition> c = homePageDao.selectCompositionBySampleId(sampleId);
				for(Composition a:c){
					s.append(a.getMaterial()+" ");
				}
				map3.put("boody", s);
			}
			if(type==1){
				//成品帘
				map3.put("boody", xiang.get("material"));
			}
			if(type==2){
				//配件
				map3.put("boody", xiang.get("material"));
			}
			
			
			xiangqing.add(map3);
			Map<String, Object> map4 = new HashMap<>();
			map4.put("boodyId", "遮光率");
			map4.put("boody", xiang.get("shading")+"%");
			xiangqing.add(map4);
			Map<String, Object> map5 = new HashMap<>();
			map5.put("boodyId", "适用场景");
			map5.put("boody", xiang.get("location"));
			xiangqing.add(map5);
			Map<String, Object> map6 = new HashMap<>();
			map6.put("boodyId", "计价单位");
			map6.put("boody", xiang.get("chargeUnit"));
			xiangqing.add(map6);
			Map<String, Object> map7 = new HashMap<>();
			map7.put("boodyId", "款式类型");
			if(xiang.get("isSty") != null && (Integer)xiang.get("isSty")==0){
				map7.put("boody", "打孔");
			}else if(xiang.get("isSty") != null && (Integer)xiang.get("isSty")==1){
				map7.put("boody", "韩褶");
			}else{
				map7.put("boody", "打孔,韩褶");
			}
			xiangqing.add(map7);
			Map<String, Object> map8 = new HashMap<>();
			map8.put("boodyId", "风格");
			map8.put("boody", xiang.get("style"));
			xiangqing.add(map8);
			Map<String, Object> map9 = new HashMap<>();
			map9.put("boodyId", "安装方式");
			map9.put("boody", xiang.get("installation"));
			//map9.put("boody",xiang.get("installation"));
			if("0".equals(xiang.get("installation"))){
				map9.put("boody", "顶裝");
			}
			if("1".equals(xiang.get("installation"))){
				map9.put("boody", "侧装");
			}
			if("2".equals(xiang.get("installation"))){
				map9.put("boody","顶裝和侧装");
			}			
			xiangqing.add(map9);
			Map<String, Object> map10 = new HashMap<>();
			map10.put("boodyId", "洗涤说明");
			map10.put("boody", xiang.get("washing"));
			xiangqing.add(map10);
		}else if(type==1){
			Map<String, Object> xiang = homePageDao.selectCpinlian(sampleId);
			List<Double> list = homePageDao.selectMenfu(sampleId);
			String methods = "门幅";
			for(int a=0;a<list.size();a++){
				if(a==list.size()-1){
					methods += list.get(a);
				}else{
					methods += list.get(a)+",";
				}
			}
			List<String> list2 = homePageDao.selectShiyong(sampleId);
			String location = "";
			for(int a=0;a<list2.size();a++){
				if(a==list2.size()-1){
					location += list2.get(a);
				}else{
					location += list2.get(a)+",";
				}
			}
			xiang.put("methods", methods);
			xiang.put("location", location);
			Map<String, Object> map1 = new HashMap<>();
			map1.put("boodyId", "品牌");
			map1.put("boody", change(xiang.get("brand")));
			xiangqing.add(map1);
			Map<String, Object> map2 = new HashMap<>();
			map2.put("boodyId", "商品号");
			map2.put("boody", change(xiang.get("sampleId")));
			xiangqing.add(map2);
			Map<String, Object> map3 = new HashMap<>();
			map3.put("boodyId", "材质");
			map3.put("boody", change(xiang.get("material")));
			xiangqing.add(map3);
			Map<String, Object> map4 = new HashMap<>();
			map4.put("boodyId", "功能");
			map4.put("boody", change(xiang.get("functions")));
			xiangqing.add(map4);
			Map<String, Object> map5 = new HashMap<>();
			map5.put("boodyId", "适用场景");
			map5.put("boody", change(xiang.get("location")));
			xiangqing.add(map5);
			Map<String, Object> map6 = new HashMap<>();
			map6.put("boodyId", "计价单位");
			map6.put("boody", change(xiang.get("chargeUnit")));
			xiangqing.add(map6);
			Map<String, Object> map7 = new HashMap<>();
			map7.put("boodyId", "计量方式");
			map7.put("boody", change(xiang.get("methods")));
			xiangqing.add(map7);
			Map<String, Object> map8 = new HashMap<>();
			map8.put("boodyId", "安装方式");
			map8.put("boody", change(xiang.get("installation")));
			xiangqing.add(map8);
			Map<String, Object> map9 = new HashMap<>();
			map9.put("boodyId", "使用方法");
			map9.put("boody", change(xiang.get("methodUse")));
			xiangqing.add(map9);
		}else{
			Map<String, Object> xiang = homePageDao.selectPeijianX(sampleId);
			Map<String, Object> map1 = new HashMap<>();
			map1.put("boodyId", "品牌");
			map1.put("boody", change(xiang.get("brand")));
			xiangqing.add(map1);
			Map<String, Object> map2 = new HashMap<>();
			map2.put("boodyId", "商品号");
			map2.put("boody", change(xiang.get("sampleId")));
			xiangqing.add(map2);
			Map<String, Object> map3 = new HashMap<>();
			map3.put("boodyId", "材质");
			map3.put("boody", change(xiang.get("material")));
			xiangqing.add(map3);
			Map<String, Object> map4 = new HashMap<>();
			map4.put("boodyId", "安装方式");
			map4.put("boody", change(xiang.get("installation")));
			xiangqing.add(map4);
		}
		Map<String, Object> map = new HashMap<>();
		map.put("Tuwen", Tuwen);
		map.put("Kuanshi", Kuanshi);
		map.put("table", xiangqing);
		BuluResult buluResult = new BuluResult();
		buluResult.setStatus(0);
		buluResult.setData(map);
		return buluResult;
	}

	/**
	 * 对一些返回结果进行判断，并给出处理结果
	 * @param object
	 * @return
	 */
	public Object change(Object object){
		if (object == null || "".equals(object))return "暂无";
		return object;
	}

	//查询满多少面安装测量费
	public BuluResult selectRegion(String city) {
		Map<String, Object> map = homePageDao.selectMjian(city);
		String quotes = (String)map.get("beginString")+map.get("money")+map.get("overString");
		BuluResult buluResult = new BuluResult();
		buluResult.setStatus(0);
		buluResult.setData(quotes);
		return buluResult;
	}

	//查询测量安装
	public BuluResult selectCeliang(Integer sampleId) {
		List<Map<String, String>> Celiang = homePageDao.selectCeliang(sampleId);
		BuluResult buluResult = new BuluResult();
		buluResult.setStatus(0);
		buluResult.setData(Celiang);
		return buluResult;
	}

	//查询热搜
	public BuluResult selectHotSearch() {
		List<String> list = homePageDao.selectHotSearch();
		BuluResult buluResult = new BuluResult();
		buluResult.setStatus(0);
		buluResult.setData(list);
		return buluResult;
	}

	//平板图文详情
	public BuluResult selectPingban(Integer sampleId, Integer type) {
		List<Map<String,Object>> Tuwen = homePageDao.selectTuwen(sampleId);
		List<Map<String, String>> Kuanshi = homePageDao.selectKuanshi(sampleId);
		List<List<Map<String, Object>>> xiangqing = new ArrayList<>();
		if(type==0){
			Map<String, Object> xiang = homePageDao.selectXiangqing(sampleId);
			List<String> list = homePageDao.selectStyleContent(sampleId);
			String style = "";
			for(int a=0;a<list.size();a++){
				if(a==list.size()-1){
					style += list.get(a);
				}else{
					style += list.get(a)+",";
				}
			}
			List<String> list2 = homePageDao.selectShiyong(sampleId);
			String location = "";
			for(int a=0;a<list2.size();a++){
				if(a==list2.size()-1){
					location += list2.get(a);
				}else{
					location += list2.get(a)+",";
				}
			}
			xiang.put("style", style);
			xiang.put("location", location);
			List<Map<String, Object>> list3 = new ArrayList<>();
			Map<String, Object> map1 = new HashMap<>();
			map1.put("boodyId", "品牌");
			map1.put("boody", xiang.get("brand"));
			list3.add(map1);
			Map<String, Object> map2 = new HashMap<>();
			map2.put("boodyId", "商品号");
			map2.put("boody", xiang.get("sampleId"));
			list3.add(map2);
			xiangqing.add(list3);
			List<Map<String, Object>> list4 = new ArrayList<>();
			Map<String, Object> map3 = new HashMap<>();
			map3.put("boodyId", "材质");
			if(type==0){
				//布艺帘
				StringBuffer s=new StringBuffer();
				List<Composition> c = homePageDao.selectCompositionBySampleId(sampleId);
				for(Composition a:c){
					s.append(a.getMaterial()+" ");
				}
				map3.put("boody", s);
			}
			if(type==1){
				//成品帘
				map3.put("boody", xiang.get("material"));
			}
			if(type==2){
				//配件
				map3.put("boody", xiang.get("material"));
			}
			list4.add(map3);
			Map<String, Object> map4 = new HashMap<>();
			map4.put("boodyId", "遮光率");
			map4.put("boody", xiang.get("shading")+"%");
			list4.add(map4);
			xiangqing.add(list4);
			List<Map<String, Object>> list5 = new ArrayList<>();
			Map<String, Object> map5 = new HashMap<>();
			map5.put("boodyId", "适用场景");
			map5.put("boody", xiang.get("location"));
			list5.add(map5);
			Map<String, Object> map6 = new HashMap<>();
			map6.put("boodyId", "计价单位");
			map6.put("boody", xiang.get("chargeUnit"));
			list5.add(map6);
			xiangqing.add(list5);
			List<Map<String, Object>> list6 = new ArrayList<>();
			Map<String, Object> map7 = new HashMap<>();
			map7.put("boodyId", "款式类型");
			if(xiang.get("isSty") != null && (Integer)xiang.get("isSty")==0){
				map7.put("boody", "打孔");
			}else if(xiang.get("isSty") != null && (Integer)xiang.get("isSty")==1){
				map7.put("boody", "韩褶");
			}else{
				map7.put("boody", "打孔,韩褶");
			}
			list6.add(map7);
			Map<String, Object> map8 = new HashMap<>();
			map8.put("boodyId", "风格");
			map8.put("boody", xiang.get("style"));
			list6.add(map8);
			xiangqing.add(list6);
			List<Map<String, Object>> list7 = new ArrayList<>();
			Map<String, Object> map9 = new HashMap<>();
			map9.put("boodyId", "安装方式");
			if("0".equals(xiang.get("installation"))){
				map9.put("boody", "顶裝");
			}
			if("1".equals(xiang.get("installation"))){
				map9.put("boody", "侧装");
			}
			if("2".equals(xiang.get("installation"))){
				map9.put("boody","顶裝和侧装");
			}
			list7.add(map9);
			Map<String, Object> map10 = new HashMap<>();
			map10.put("boodyId", "洗涤说明");
			map10.put("boody", xiang.get("washing"));
			list7.add(map10);
			xiangqing.add(list7);
		}else if(type==1){
			Map<String, Object> xiang = homePageDao.selectCpinlian(sampleId);
			List<Double> list = homePageDao.selectMenfu(sampleId);
			String methods = "门幅:";
			for(int a=0;a<list.size();a++){
				if(a==list.size()-1){
					methods += list.get(a);
				}else{
					methods += list.get(a)+",";
				}
			}
			List<String> list2 = homePageDao.selectShiyong(sampleId);
			String location = "";
			for(int a=0;a<list2.size();a++){
				if(a==list2.size()-1){
					location += list2.get(a);
				}else{
					location += list2.get(a)+",";
				}
			}
			xiang.put("methods", methods);
			xiang.put("location", location);
			List<Map<String, Object>> list3 = new ArrayList<>();
			Map<String, Object> map1 = new HashMap<>();
			map1.put("boodyId", "品牌");
			map1.put("boody", xiang.get("brand"));
			list3.add(map1);
			Map<String, Object> map2 = new HashMap<>();
			map2.put("boodyId", "商品号");
			map2.put("boody", xiang.get("sampleId"));
			list3.add(map2);
			xiangqing.add(list3);
			List<Map<String, Object>> list4 = new ArrayList<>();
			Map<String, Object> map3 = new HashMap<>();
			map3.put("boodyId", "材质");
			map3.put("boody", xiang.get("material"));
			list4.add(map3);
			Map<String, Object> map4 = new HashMap<>();
			map4.put("boodyId", "功能");
			map4.put("boody", xiang.get("functions"));
			list4.add(map4);
			xiangqing.add(list4);
			List<Map<String, Object>> list5 = new ArrayList<>();
			Map<String, Object> map5 = new HashMap<>();
			map5.put("boodyId", "适用场景");
			map5.put("boody", xiang.get("location"));
			list5.add(map5);
			Map<String, Object> map6 = new HashMap<>();
			map6.put("boodyId", "计价单位");
			map6.put("boody", xiang.get("chargeUnit"));
			list5.add(map6);
			xiangqing.add(list5);
			List<Map<String, Object>> list6 = new ArrayList<>();
			Map<String, Object> map7 = new HashMap<>();
			map7.put("boodyId", "计量方式");
			map7.put("boody", xiang.get("methods"));
			list6.add(map7);
			Map<String, Object> map8 = new HashMap<>();
			map8.put("boodyId", "安装方式");
			map8.put("boody", xiang.get("installation"));
			list6.add(map8);
			xiangqing.add(list6);
			List<Map<String, Object>> list7 = new ArrayList<>();
			Map<String, Object> map9 = new HashMap<>();
			map9.put("boodyId", "使用方法");
			map9.put("boody", xiang.get("methodUse"));
			list7.add(map9);
			xiangqing.add(list7);
		}else{
			Map<String, Object> xiang = homePageDao.selectPeijianX(sampleId);
			List<Map<String, Object>> list = new ArrayList<>();
			Map<String, Object> map1 = new HashMap<>();
			map1.put("boodyId", "品牌");
			map1.put("boody", xiang.get("brand"));
			list.add(map1);
			Map<String, Object> map2 = new HashMap<>();
			map2.put("boodyId", "商品号");
			map2.put("boody", xiang.get("sampleId"));
			list.add(map2);
			xiangqing.add(list);
			List<Map<String, Object>> list1 = new ArrayList<>();
			Map<String, Object> map3 = new HashMap<>();
			map3.put("boodyId", "材质");
			map3.put("boody", xiang.get("material"));
			list1.add(map3);
			Map<String, Object> map4 = new HashMap<>();
			map4.put("boodyId", "安装方式");
			map4.put("boody", xiang.get("installation"));
			list1.add(map4);
			xiangqing.add(list1);
		}
		Map<String, Object> map = new HashMap<>();
		map.put("Tuwen", Tuwen);
		map.put("Kuanshi", Kuanshi);
		map.put("table", xiangqing);
		BuluResult buluResult = new BuluResult();
		buluResult.setStatus(0);
		buluResult.setData(map);
		return buluResult;
	}

	
}
